package com.hnust.root.service.forword.wx;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hnust.root.dao.entity.domain.forward.University;
import com.hnust.root.dao.mapper.wx.UniversityMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Service
public class UniversityService {

    @Autowired
    private UniversityMapper universityMapper;

    //通过学校名模糊搜索学校
    @Cacheable(cacheNames = "mydemo:university",key = "#name")
    public List<University> getUniversityByName(String name) {
        List<University> list;
        if (!StrUtil.isEmpty(name)){
            list = universityMapper.selectList(new QueryWrapper<University>().like("name", name));
        } else {
            list = Collections.EMPTY_LIST;
        }
        return list;
    }
}
